<template>
  <div class="select-tab">
    <span
      :class="{selected: selidx===index, 'disabled': item.disabled}"
      class="select-tab-item"
      @click="handleDeal(item,index)"
      v-for="(item,index) in tabarr"
      :key="index"
    >{{item.text}}</span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selidx: 0
    }
  },
  props: {
    tabarr: {
      type: Array,
      default() {
        return []
      },
      required: true
    }
  },
  methods: {
    changeIndex(i) {
      if (typeof i === 'number' && i < this.tabarr.length) {
        this.selidx = 1
        this.$emit('selectData', this.tabarr[i])
      }
    },
    handleDeal(data, idx) {
      if (data.disabled) {
        return
      }
      // console.log(data)
      this.selidx = idx
      this.$emit('selectData', data)
    }
  }
}
</script>

<style lang="scss">
.select-tab {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 10px;
  .select-tab-item {
    font-size: 16px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    color: rgba(42, 44, 47, 1);
    text-align: center;
    display: block;
    padding: 6px 12px;
    cursor: pointer;
    background: rgba(75, 121, 254, 1);
    border-radius: 24px;
    color: rgba(255, 255, 255, 1);
  }
  .select-tab-item {
    &.selected {
      background: #ffffff;
      border-radius: 24px;
      color: rgba(75, 121, 254, 1);
    }
    &.disabled {
      background: transparent;
      border-radius: 24px;
      color: #ccc;
      cursor: not-allowed;
    }
  }
}
</style>
